﻿#include "Depacker.h"

using namespace FCMiddleware;

Depacker::Depacker()
{
	_buf_used = 0;
}

Depacker::~Depacker()
{
}

void Depacker::remove(unsigned int size)
{
	unsigned char buf[DEPACKER_BUFF_SIZE];
	_buf_used -= size;

	memcpy(buf, _buf + size, _buf_used);
	memcpy(_buf, buf, _buf_used);
}

void Depacker::clear()
{
	_buf_used = 0;
}

unsigned short Depacker::push(unsigned int size)
{
	if (_buf_used + size > DEPACKER_BUFF_SIZE)
		size = DEPACKER_BUFF_SIZE - _buf_used;
	_buf_used += size;
	return size;
}

unsigned short Depacker::push(unsigned char* data, unsigned int size)
{
	if (_buf_used + size > DEPACKER_BUFF_SIZE)
		size = DEPACKER_BUFF_SIZE - _buf_used;

	memcpy(_buf + _buf_used, data, size);
	_buf_used += size;
	return size;
}

unsigned char* Depacker::buf(unsigned int* size)
{
	*size = DEPACKER_BUFF_SIZE - _buf_used;
	return _buf + _buf_used;
}


